package com.zchat.android.views.menus;


import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zchat.android.app.LauncherApplication;
import com.zchat.api.ZChat;
import com.zchat.api.util.Resolution;

public abstract class MenuItem extends LinearLayout {
	protected ZChat zchat;
	protected Context context;
	
		/**
		 * @param context
		 */
		public MenuItem(Context context) {
			super(context);
		}

		private int bgResid;
		private int imgResid1;
		private int imgResid2;
		private int textResid;
		private int textColor1;
		private int textColor2;
		
		/**
		 * 
		 * @param context
		 * @param bgResid 活动状态view的背景图片
		 * @param imgResid1 非活动状态图标
		 * @param imgResid2 活动状态图标
		 * @param textResid 文字
		 * @param textColor1 非活动状态文字颜色
		 * @param textColor2 活动状态文字颜色
		 */
		public MenuItem(Context context, int bgResid, 
				int imgResid1, int imgResid2, 
				int textResid, 
				int textColor1, int textColor2) {
			super(context);
			// TODO Auto-generated constructor stub
			this.bgResid = bgResid;
			this.imgResid1 = imgResid1;
			this.imgResid2 = imgResid2;
			this.textResid = textResid;
			this.textColor1 = textColor1;
			this.textColor2 = textColor2;
			
			this.context = context;
			zchat = 
					((LauncherApplication)((Activity)context).getApplication()).getZChat(context);
			
			initItem(context);
		}

		private ImageView image;
		private TextView text;
		
		private boolean isNormal = true;
		
		/**
		 * @param context
		 * @param textResid 
		 * @param imgResid 
		 */
		private void initItem(Context context) {
			// TODO Auto-generated method stub
			this.setGravity(Gravity.CENTER);
			this.setOrientation(LinearLayout.VERTICAL);
			
			image = new ImageView(context);
			this.addView(image, (int)(Resolution.getInstance().getScreenWidth() * 0.078), (int)(Resolution.getInstance().getScreenWidth() * 0.078));
			
			text = new TextView(context);
			text.setText(textResid);
			text.setPadding(0, 5, 0, 0);
			this.addView(text, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			
			toNormal();
		}
		
		/**
		 * 正常情况下
		 */
		public void toNormal() {
//			this.setBackgroundColor(bgResid1);	//背景,因全透明，则不设置
			this.setBackgroundColor(Color.TRANSPARENT);
			image.setImageResource(imgResid1);	//图标
			text.setTextColor(textColor1);		//文字色彩
			this.isNormal = true;
		}
		
		/**
		 * 点击高亮情况下
		 */
		public void toActive() {
			this.setBackgroundResource(bgResid);
			image.setImageResource(imgResid2);	//图标
			text.setTextColor(textColor2);		//文字色彩
			this.isNormal = false;
		}

		/**
		 * @return the isNormal
		 */
		public boolean isNormal() {
			return isNormal;
		}
		
		public abstract void onClick();
		

}
